// KetonalConfigWindow.cpp: implementation of the KetonalConfigWindow class.
//
//////////////////////////////////////////////////////////////////////
#include "KetonalFormEditorWindow.h"
#include "KetonalConfigComponent.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

KetonalFormEditorWindow::KetonalFormEditorWindow(KetonalConfigComponent *_parent, KetonalConfig *_c)
{
	config		= _c;
	parent		= _parent;
	formFields	= 1;

	closeButton = LookAndFeel::getDefaultLookAndFeel().createDocumentWindowButton (DocumentWindow::closeButton);
	closeButton->addButtonListener (this);

	addAndMakeVisible (formEditor = new KetonalFormEditor (config, this));
	addAndMakeVisible (closeButton);
	setBounds (parent->getScreenX()+parent->getWidth()+3, parent->getScreenY(), 256, 152*formFields);

	setVisible (true);
	setAlwaysOnTop (true);

	addToDesktop (ComponentPeer::windowIsTemporary);
}

KetonalFormEditorWindow::~KetonalFormEditorWindow()
{
	deleteAndZero (formEditor);
	deleteAndZero (closeButton);
}

void KetonalFormEditorWindow::resized()
{
	setBounds (parent->getScreenX()+parent->getWidth()+3, parent->getScreenY(), 256, 152*formFields);
	closeButton->setBounds (236,4,16,16);
}

void KetonalFormEditorWindow::buttonClicked (Button *btn)
{	
	if (btn == closeButton)
	{
		parent->closeFormEditor();
		delete this;
	}
}

void KetonalFormEditorWindow::setElements (int n)
{
	formFields = n;
	resized();
	Logger::writeToLog (String::formatted (T("FormEditorWindow: %d %d"), getWidth(), getHeight()));
}